﻿using System;
using System.Reflection;
using System.Windows.Media;
using MusicKeys.Properties;

namespace MusicKeys {
	class Program {
		static MediaPlayer player;
		static string song;
		static void Main(string[ ] args) {
			player = new MediaPlayer( );
			player.Volume = 1.0;
			player.MediaEnded += new EventHandler(player_MediaEnded);
			string path = System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly( ).Location);
			bool running = true;
			while (running) {
				ConsoleKey activKey = Console.ReadKey( ).Key;
				switch (activKey) {
					case ConsoleKey.Escape:
						running = false;
						break;
					case ConsoleKey.Applications:
						if (player.Position != TimeSpan.Zero && player.Position != player.NaturalDuration) {
							player.Stop( );
							Console.WriteLine(Resources.text_end + " Music\\" + song + ".wav");
						}
						break;
					default:
						Console.SetCursorPosition(0, Console.CursorTop);
						if (System.IO.File.Exists(path + "\\Music\\" + activKey.ToString( ) + ".wav")) {
							if (player.Position == TimeSpan.Zero || player.Position == player.NaturalDuration) {
								song = activKey.ToString( );
								Console.WriteLine(Resources.text_play + " Music\\" + song + ".wav");
								player.Open(new Uri(path + "\\Music\\" + song + ".wav"));
								player.Play( );
							} else
								Console.WriteLine(Resources.text_isbusy + " Music\\" + song + ".wav");
						} else
							Console.WriteLine(Resources.text_notexits + " Music\\" + activKey.ToString( ) + ".wav");
						break;
				}

			}
		}

		static void player_MediaEnded(object sender, EventArgs e) {
			Console.WriteLine(Resources.text_end + " Music\\" + song + ".wav");
		}
	}
}